<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>停时记录</title>
    <link rel="stylesheet" href="../../../assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../../assets/module/admin.css?v=317"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<!-- 加载动画 -->
<div class="page-loading">
    <div class="ball-loader">
        <span></span><span></span><span></span><span></span>
    </div>
</div>
<!-- 正文开始 -->
<form class="layui-form" id="formAdvForm" lay-filter="formAdvForm">
    <div class="layui-fluid" style="padding-bottom: 75px;">
        <div class="layui-card">
            <div class="layui-card-header">停时日志
            </div>
            <div class="layui-card-body">
                <div class="layui-form-item layui-row">
                    <div class="layui-inline layui-col-md5">
                        <label class="layui-form-label layui-form-required">生产线:</label>
                        <div class="layui-input-block">
                            <select name="lineNum">
                                <option value="1">大线</option>
                                <option value="2">中线</option>
                                <option value="3">小线</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline layui-col-md5">
                        <label class="layui-form-label layui-form-required">停时类型:</label>
                        <div class="layui-input-block">
                            <input id="demoCascader9" placeholder="请选择" name="delayType" class="layui-hide"
                                   lay-verType="tips" lay-verify="required" required
                            />
                        </div>
                    </div>
                    <br>
                    <div class="layui-inline layui-col-md5">
                        <label class="layui-form-label layui-form-required">停时开始时间:</label>
                        <div class="layui-input-block">
                            <input name="delayStartTime" placeholder="停时时间" class="layui-input"
                                   lay-verType="tips" lay-verify="required" autocomplete="off" required id="test1"/>
                        </div>

                    </div>
                    <div class="layui-inline layui-col-md5">
                        <label class="layui-form-label layui-form-required">停时结束时间:</label>
                        <div class="layui-input-block">
                            <input name="delayEndTime" placeholder="停时时间" class="layui-input"
                                   lay-verType="tips" lay-verify="required" autocomplete="off" required id="test2"/>
                        </div>

                    </div>

                    <div class="layui-inline layui-col-md8">
                        <label class="layui-form-label">备注说明:</label>
                        <div class="layui-input-block">
                            <input name="comment" placeholder="请输入备注说明" class="layui-input"/>
                        </div>
                    </div>
                </div>
            </div>
            <div>
                <button type="reset" class="layui-btn layui-btn-primary">&emsp;重置&emsp;</button>
                <a class="layui-btn" lay-filter="formAdvSubmit" lay-submit>&emsp;提交&emsp;</a>
            </div>
        </div>
        <div class="layui-card">
            <div class="layui-card-header">记录日志</div>
            <div class="layui-card-body">
                <table id="formAdvTable" lay-filter="formAdvTable"></table>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript" src="../../../assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="../../../assets/js/common.js?v=317"></script>
<script type="text/javascript" src="../../../assets/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../../../assets/js/js.cookie.min.js"></script>
<script type="text/javascript" src="../../../assets/js/sqjx.js"></script>
<script>
    layui.use(['layer', 'form', 'table', 'laydate', 'cascader'], function () {
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var laydate = layui.laydate;
        var cascader = layui.cascader;
        var data = doPostSync('/office/tDict/queryDelayDict').obj;
        // 搜索功能
        var delayType;
        cascader.render({
            elem: '#demoCascader9',
            data: data,
            filterable: true,
            multiple: true,
            onChange: function (values, data) {
                delayType = data.value;
            }
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#test1', //指定元素
            type: 'datetime',
            trigger: 'click'
        });
        laydate.render({
            elem: '#test2', //指定元素
            type: 'datetime',
            trigger: 'click'
        });


        // /* 渲染表格 */
        var insTb = table.render({
            elem: '#formAdvTable',
            url: '/report/reportWrite/queryReportWriteList',
            page: true,
            method: 'post',
            request: {
                pageName: 'page',
                limitName: 'rows',
            },
            cellMinWidth: 100,
            cols: [[
                {
                    field: 'lineNum', title: '生产线', width: '80', align: 'center', templet(row) {
                        return row.lineNum == 1 ? '大线' : (row.lineNum == 2 ? '中线' : row.lineNum == 3 ? '小线' : '未知参数')
                    }
                },
                // {
                //     field: 'preport', title: '停时时段',width:'200', align: 'center', templet(row) {
                //         return row.preport + "日" + row.hour + "时";
                //     }
                // },
                {field: 'startTime', title: '开始时间', align: 'center', width: '200'},
                {field: 'endTime', title: '结束时间', align: 'center', width: '200'},
                {field: 'crtUserName', title: '记录人', align: 'center', width: '100'},

                {
                    field: 'delayType', title: '停时类型', width: '160', align: 'center', templet(row) {
                        var res = doPostSync('/office/tDict/getDictValue?dictCode=' + row.delayType).obj;
                        return res;
                    }
                },
                {field: 'delayMin', title: '停时时间', align: 'center', width: 100},
                {
                    field: 'crtDate', title: '记录时间', width: '200', align: 'center', templet(row) {
                        return dateFormatter(row.crtDate)
                    }
                },
                {field: 'comment', title: '备注', align: 'center', width: 100},
                {
                    field: '操作', title: '操作', fixed: 'right', width: '180', align: 'center', templet(row) {
                        return `
                                <!--<input type="checkbox" name="zzz" lay-skin="switch" lay-text="确认|未确认">-->
                               <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" ">删除</a>`;
                    }
                },
            ]],
            parseData: function (res) {
                return {
                    "code": 0,
                    "msg": "",
                    "count": res.obj.total,
                    "data": res.obj.rows
                }
            }
        });
        /* 监听表单提交 */
        form.on('submit(formAdvSubmit)', function (data) {
            var startTime = data.field.delayStartTime;
            var endTime = data.field.delayEndTime;
            var a = getDate(startTime);
            var b = getDate(endTime);
            var count = b.getTime() - a.getTime();
            if (count <= 0) {
                showAlert("开始时间不能大于结束时间，请重新选择时段");
                return false;
            } else {
                if (b.getTime() - a.getTime() > 28800000) {
                    showAlert("记录时长不能大于8小时,请重新选择时段");
                    return false;
                }
            }
            var param = {
                startTime: startTime,
                endTime: endTime,
                comment: data.field.comment,
                delayType: delayType,
                crtUserName: getUserName(),
                crtUserCode: getAccount(),
                lineNum: data.field.lineNum
            };
            layer.confirm('确认提交？', function () {
                var result = doPostSync('/report/reportWrite/addReportWrite', param);
                if (result.code == 200) {
                    closeDialog();
                    showAlert('日志已保存', 1);
                    insTb.reload();
                } else {
                    showAlert(res.msg);
                }
            });

        });
        table.on('tool(formAdvTable)', function (obj) {
            if (obj.event == 'del') {
                layer.confirm('确认删除该条日志？', function () {
                    $.post('/report/reportWrite/deleteReportWrite', {delayId: obj.data.delayId}, function (res) {
                        if (res.code == 200) {
                            closeDialog();
                            showAlert('删除成功', 1);
                            insTb.reload({page: {curr: 1}});
                        } else {
                            showAlert('删除失败');
                        }
                    })
                })
            }
        })
    });
</script>
</body>
</html>
